home *** CD-ROM | disk | FTP | other *** search
- Path: info.spt.net.cn!usenet
- From: txwang@public.sta.net.cn (Wang TianXing)
- Newsgroups: comp.lang.c++
- Subject: Re: Question about destructor...
- Date: Sat, 20 Jan 1996 14:50:28 GMT
- Organization: No Organization
- Message-ID: <4dqv04$nua@info.sta.net.cn>
- References: <4ce9mk$atg@eng_ser1.erg.cuhk.hk> <4cqrei$par@isoit109.bbn.hp.com> <4dkahd$lv9@alibaba.kmit.sk>
- NNTP-Posting-Host: ts2-3.sta.net.cn
- X-Newsreader: Forte Free Agent 1.0.82
-
- brano@alibaba (Brano Zahradnik) wrote:
-
- | Manfred_Lange (Manfred_Lange@bbn.hp.com) wrote:
- | : ywleung@cs.cuhk.hk (Marty McFly) wrote:
- | : >Dear All,
- | : >
- | : > I now have 2 classes A and B. B is a derived class of A. However,
- | : >the internal implementation of A is not known, i.e., the private members of
- | : >class A are not provided, only the public members are given. But class B is
- | : >implemented by myself. So what should be written in the destructor of B so
- | : >that all the private members inherited from A are also "deleted"?
-
- | : I saw all the answers you got for your question. It is true, that you don't have
- | : to care for the destructor in the baseclass.
-
- | : But there is another aspect of the problem, that is important to know. Take the
- | : following sample:
-
- | : class Base
- | : {
- | : ~Base();
- | : };
-
- | : class Derived : public Base
- | : {
- | : ~Derived();
- | : };
-
- | : ..
-
- | : { Base* aBase;
-
- | : aBase = new Derived();
-
- | : ...
-
- | : delete aBase;
-
- | : ..
-
-
- | : Which destructor will be called when executing "delete aBase()" ?
-
- | I think, that destructors are calling in reverse order than constructors.
- | In this example: ~Derived,~Base
- NO. Only ~Base() will be called. So, that's a problem.
-
- If you do know aBase is pointing to a Derived, you can:
-
- delete (Derived *)aBase;
-
- If not, you have to declare ~Base() as virtual, but this requires that
- you have the source code of the Base class.
-
- | Q: Why you need rewrite destructor of base ??
-
- See above. (BTW, I don't think the original poster realized that he
- have to do this.)
-
- ---
- Wang TianXing
- txwang@public.sta.net.cn
-
-
-